﻿using RPAVIEW.util;
using RPAVIEW.views.controlLibrary;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.util;
using System.Windows;
using System.Windows.Controls;

namespace RPAVIEW.views.EditPage.flows.ReceiveEmailN {
    /// <summary>
    /// Input.xaml 的交互逻辑
    /// </summary>
    public partial class Input:BaseParamViewAction{
        public Input() {
            InitializeComponent();
            MailTypeChanged(null, null);
            ReceiveEmailNParam param = ParamUtil.GetCurrentParam<ReceiveEmailNParam>();
            if(param.SaveAttachFile ?? false) {
                this.savepathrow.Height = GridLength.Auto;
            } else { 
                this.savepathrow.Height = new GridLength(0);
            }
            this.password.Password = param.Password;
        }

        public override void UpdateSource() {
            this.mailType.GetBindingExpression(ComboBox.SelectedIndexProperty).UpdateSource();
            this.serverName.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.port.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.ssl.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
            this.account.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            //this.password.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            //this.mailNum.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            //this.unReadMail.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
            this.saveAttachFile.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
            this.savePath.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            ReceiveEmailNParam param = this.DataContext as ReceiveEmailNParam;
            param.Password = this.password.Password;
        }

        private void SelectSavePath(object sender, RoutedEventArgs e) {
            System.Windows.Forms.FolderBrowserDialog saveDialog =  FileUtil.OpenFloderSelectDialog();
            System.Windows.Forms.DialogResult dialogResult = saveDialog.ShowDialog();
            //按下确定选择的按钮  
            if(dialogResult == System.Windows.Forms.DialogResult.OK) {
                //记录选中的目录
                this.savePath.Text = saveDialog.SelectedPath;
            }
        }

        private void SaveAttachChanged(object sender, RoutedEventArgs e) {
            if(this.saveAttachFile.IsChecked ?? false) {
                this.savepathrow.Height = GridLength.Auto;
            } else { 
                this.savepathrow.Height = new GridLength(0);
            }
        }

        private void MailTypeChanged(object sender, SelectionChangedEventArgs e) {
            if(this.mailType.SelectedIndex == 3) {
                this.imaprow.Height = GridLength.Auto;
                this.portrow.Height = GridLength.Auto;
            } else { 
                this.imaprow.Height = new GridLength(0);
                this.portrow.Height = new GridLength(0);
            }
        }
    }
}
